<?php

class ECOMApiResponder {

    //put your code here

    public static function Respond($obj, $expiryDate, $format = 'json') {
        if ($format == 'json') {
            header("Content-Type: application/json");
            if ($obj instanceof ECOMResult) {
                header("HTTP/1.1 " . $obj->code . ' ' . self::_getStatusCodeMessage($obj->code));
            }
            echo CJSON::encode($obj);
            die;
        }
    }

    public static function RespondDirect($txt, $expiryDate, $format = 'json') {
        if ($format == 'json') {
            header("Content-Type: application/json");
        }
        echo $txt;
    }

    private static function _getStatusCodeMessage($status) {
        // these could be stored in a .ini file and loaded
        // via parse_ini_file()... however, this will suffice
        // for an example
        $codes = Array(
            200 => 'OK',
            400 => 'Bad Request',
            401 => 'Unauthorized',
            402 => 'Payment Required',
            403 => 'Forbidden',
            404 => 'Not Found',
            412 => 'Precondition Failed',
            500 => 'Internal Server Error',
            501 => 'Not Implemented',
        );
        return (isset($codes[$status])) ? $codes[$status] : '';
    }

}

?>
